/*
 * @Author: hrg
 * @Date: 2024-01-30 09:07:02
 * @LastEditTime: 2024-01-30 15:18:11
 * @FilePath: \study_go\study08_gin\gin_dome_11\mian.go
 * @Description:中间件的练习
 */
package main

import (
	"fmt"
	"time"

	"github.com/gin-gonic/gin"
)

func middleware(c *gin.Context) {

	t := time.Now()

	c.Next()

	t2 := time.Since(t)
	fmt.Println("time：", t2)

}

func main() {
	r := gin.New()

	r.Use(middleware)

	test := r.Group("/test")

	test.GET("/t1", t1Func)
	test.GET("/t2", t2Func)

	r.Run(":9090")

}

func t1Func(c *gin.Context) {
	time.Sleep(3 * time.Second)
	c.JSON(200, "dfasdf")
}

func t2Func(c *gin.Context) {
	time.Sleep(5 * time.Second)
	c.JSON(200, "2341234")

}
